package com.kaifamiao.www.ioDemo.do0922;

import java.io.*;
import java.nio.charset.Charset;
import java.util.*;

public class CSBTest {
    public static void main(String[] args) {
        String path = "E:\\kaifamiao\\workspace\\idea--space\\io\\csb.txt";
        try (FileReader file = new FileReader(path, Charset.forName("gbk"));
             BufferedReader br = new BufferedReader(file);
             FileWriter fw = new FileWriter("E:\\kaifamiao\\workspace\\idea--space\\io\\csb11.txt");
             BufferedWriter bw = new BufferedWriter(fw);
        ){
            ArrayList<String> list = new ArrayList<>();
            String line ="";
            while ((line = br.readLine())!=null){
//                System.out.println(line);
                list.add(line);
            }
            System.out.println(list);
            int s = list.size();
            System.out.println(s);
            //排序
            Collections.sort(list);
            //迭代输出
            Iterator<String> it = list.iterator();
            while (it.hasNext()){
                String csb = (String) it.next();
                    bw.write(csb);
                    bw.newLine();
                System.out.println(csb);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
   public List<String> sortlist(List<String> list){
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                //截取第一个字符
                char c = o1.charAt(0);
                char c1 = o2.charAt(0);
                return c-c1;
            }
        });
        return list;
    }
}

